﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.IO;
using School.Entities;
using School.Common;
using System.Data.Entity;
using School.Admission;
using System.Text;



namespace School.Pages.Admission
{
    public partial class StatusReportEntry : System.Web.UI.Page
    {
        //***************** This is function to handle page when page load ***************************
        //-**********************************************************************




        protected void Page_Load(object sender, EventArgs e)
        {
            if ((IQueryable<int>)Session["privilage"] != null)
            {
                var x = (IQueryable<int>)Session["privilage"];

                if (x.Contains(1011) == true)
                {

                    if (!(Page.IsPostBack))
                    {

                        Fillcrls();
                        InitializeControls();
                    }

                }
                else
                    Response.Redirect("../organization/no_privelege.aspx");
            }
            else
                Response.Redirect("../organization/no_privelege.aspx");
        }

        # region "Fill all crls"

        //***************** This is function to fill crl  ***************************
        //-**************************************************************************

        protected void Fillcrls()
        {

            ddlSearchcampus_Id.DataSource = Structure.GetCampuses();
            ddlSearchcampus_Id.DataTextField = "Name";
            ddlSearchcampus_Id.DataValueField = "Id";
            ddlSearchcampus_Id.DataBind();
            ddlSearchcampus_Id.Items.Insert(0, new ListItem("اختيار", "-1"));

            ddlSearchStatus_ID.DataSource = Student.GetAllstatus();
            ddlSearchStatus_ID.DataTextField = "Name";
            ddlSearchStatus_ID.DataValueField = "Id";
            ddlSearchStatus_ID.DataBind();
            ddlSearchStatus_ID.Items.Insert(0, new ListItem("اختيار", "-1"));


        }


        //***************** This is function to initlaize crl  ***************************
        //-**************************************************************************
        protected void InitializeControls()
        {
        }

        # endregion


        # region "Mode Handlers"

        //***************** This is function to handle page in add mode  ***************************
        //-**************************************************************************
        protected void PutFormInAddMode()
        {

        }


        //***************** This is function to handle page in brows mode  ***************************
        //-**************************************************************************

        protected void PutFormInBrwosMode()
        {
      
            pnlbrows.Visible = false;

        }

        #endregion






        # region   "Execute commands sent to the form"



        //***************** This is function to handle page when Puser click in الغاء btn  ***************************
        //-**************************************************************************
        protected void btnCancel_Click(object sender, EventArgs e)
        {
     
        }


        //***************** This is function to handle page when Puser click in اضافة btn  ***************************
        //-**************************************************************************

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            InitializeControls();
            pnlbrows.Visible = false;
            pnldetails.Visible = false;
        }

        //***************** This is function to handle page when Puser click in انهاء btn  ***************************
        //-**************************************************************************


        protected void btnend_Click(object sender, EventArgs e)
        {
            
            pnlbrows.Visible = true;
        }

        # endregion
        protected void btnprnt_Click(object sender, EventArgs e)
        {
            Session["FileOrderId"] = "1004";

            
            string strbScript = "";
            strbScript = "<script language='javascript'>";
            strbScript = strbScript + "window.open('Reports/Showreport.aspx', true, 'height=800,width=800,status=no,toolbar=no,menubar=no,location=no')";
            strbScript = strbScript + "</script>";

            Response.Write(strbScript);
        }
        protected void ddlSearchcampus_Id_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddlSearchcampus_Id.SelectedIndex > 0)
            {
                ddlSearchCertificate_Id.Items.Clear();
                ddlSearchGrade_ID.Items.Clear();
                ddlSearchStage_Id.Items.Clear();
                ddlSearchCertificate_Id.DataSource = Structure.GetCertificatesByCampus(Convert.ToInt64(ddlSearchcampus_Id.SelectedValue));
                ddlSearchCertificate_Id.DataTextField = "Name";
                ddlSearchCertificate_Id.DataValueField = "Id";
                ddlSearchCertificate_Id.DataBind();
                ddlSearchCertificate_Id.Items.Insert(0, new ListItem("اختيار", "-1"));
                ddlSearchCertificate_Id.Enabled = true;
                ddlSearchGrade_ID.Enabled = false;
                ddlSearchStage_Id.Enabled = false;
            }
        }

        protected void ddlSearchCertificate_Id_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddlSearchCertificate_Id.SelectedIndex > 0)
            {
                ddlSearchStage_Id.Items.Clear();
                ddlSearchGrade_ID.Items.Clear();
                ddlSearchStage_Id.DataSource = Structure.GetStagesByCertificate(Convert.ToInt64(ddlSearchCertificate_Id.SelectedValue));
                ddlSearchStage_Id.DataTextField = "Name";
                ddlSearchStage_Id.DataValueField = "id";
                ddlSearchStage_Id.DataBind();
                ddlSearchStage_Id.Items.Insert(0, new ListItem("اختيار", "-1"));
                ddlSearchStage_Id.Enabled = true;
                ddlSearchGrade_ID.Enabled = false;


            }
        }

        protected void ddlSearchStage_Id_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddlSearchStage_Id.SelectedIndex > 0)
            {

                ddlSearchGrade_ID.Items.Clear();
                ddlSearchGrade_ID.DataSource = Structure.GetGradesByStage(Convert.ToInt64(ddlSearchStage_Id.SelectedValue));
                ddlSearchGrade_ID.DataTextField = "Name";
                ddlSearchGrade_ID.DataValueField = "id";
                ddlSearchGrade_ID.DataBind();
                ddlSearchGrade_ID.Items.Insert(0, new ListItem("اختيار", "-1"));
                ddlSearchGrade_ID.Enabled = true;


            }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            if (ddlSearchStage_Id.SelectedIndex > 0)
            {
                Session["Stage_Id"] = ddlSearchStage_Id.SelectedValue;
                if (ddlSearchGrade_ID.SelectedIndex > 0)
                {
                    Session["grade_Id"] = ddlSearchGrade_ID.SelectedValue;
                }
                else
                {
                    Session["grade_Id"] = null;
                }
                if (ddlSearchStatus_ID.SelectedIndex > 0)
                {
                    Session["statusId"] = ddlSearchStatus_ID.SelectedValue;
                }
                else
                {
                    Session["statusId"] = null;
                }

                string strbScript = "";
                strbScript = "<script language='javascript'>";
                strbScript = strbScript + "window.open('Reports/ShowStatusReport.aspx', true, 'height=600,width=800,status=no,toolbar=no,menubar=no,location=no')";
                strbScript = strbScript + "</script>";
                Response.Write(strbScript);
            }
            else
            {
                lblMessage.Text = "برجاء اختيار احد المراحل الدراسية من القائمة";
            }
        }

        protected void btnGetAll_Click(object sender, EventArgs e)
        {

        }

    }
}